package June;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Scanner;

public class Test06ArrayList01 {
    public static void main(String[] args) {
        //创建集合，泛型为创建的名为Test06ArrayList01stuClass类(泛型可以为String、integer....也可以是自己创建的类)
        ArrayList<Test06ArrayList01stuClass> stuList= new ArrayList<>();
        Test06ArrayList01stuClass s1=new Test06ArrayList01stuClass("小王",18);
        Test06ArrayList01stuClass s2=new Test06ArrayList01stuClass("小红",18);
        stuList.add(s1);
        stuList.add(s2);

        //16、17行作用是获得类成员变量的数量
        Class<?> clazz = Test06ArrayList01stuClass.class;
        Field[] fields = clazz.getDeclaredFields();

        Scanner sc=new Scanner(System.in);
        System.out.println(fields.length);

        for (int i = 0; i < 3; i++) {
            Test06ArrayList01stuClass st=new Test06ArrayList01stuClass();
            System.out.println("请输入姓名和年龄");
            String name=sc.next();

            int age= sc.nextInt();
            st.setName(name);
            st.setAge(age);
            stuList.add(st);
        }



        for (int i = 0; i < stuList.size(); i++) {
            Test06ArrayList01stuClass test06ArrayList01stuClass = stuList.get(i);
            System.out.println(test06ArrayList01stuClass);
        }

    }
}
